package com.example.module_park.home

import android.util.Log
import com.example.lib_common.base.BaseViewModel
import com.example.lib_common.base.state.Failed
import com.example.lib_common.base.state.Loading
import com.example.lib_common.base.state.RequestEvent
import com.example.lib_common.base.state.Success
import com.example.module_park.R
import com.example.module_park.model.NoticeEntityItem
import com.example.module_park.model.PackItemEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(private val repository: HomeRepository) : BaseViewModel() {

    val homeList = mutableListOf<PackItemEntity>()

    val noticeList = mutableListOf<NoticeEntityItem>()
    private val _mNotice = MutableStateFlow<RequestEvent>(Loading)
    val noticeState get() = _mNotice.asStateFlow()

    //首页公告数据
    fun getNotice(page: Int, size: Int) {
        execute(
            action = repository.getNotice(page, size),
            onStart = {
                _mNotice.value = Loading
            },
            onError = {
                Log.e("FAN", it)
                _mNotice.value = Failed(it)
            },
            onFinish = {
                noticeList.clear()
                noticeList.addAll(it.data)
                _mNotice.value = Success

                Log.e("FAN", it.data.toString())
            }
        )
    }

    //首页分类
    fun initList() {
        homeList.clear()
        homeList.add(PackItemEntity("车位登记", R.drawable.ic_parking))
        homeList.add(PackItemEntity("访客登记", R.drawable.visitor_home))
        homeList.add(PackItemEntity("物业保修", R.drawable.repair_home))
        homeList.add(PackItemEntity("考勤打卡", R.drawable.sign_home))
        homeList.add(PackItemEntity("房源信息", R.drawable.house_home))
        homeList.add(PackItemEntity("商家推荐", R.drawable.shop_home))
        homeList.add(PackItemEntity("月卡会员", R.drawable.member_home))
        homeList.add(PackItemEntity("设备管理", R.drawable.device_home))

    }


}